In LATEX, commands can have both mandatory and optional arguments,
for example in:
verbatim45#
the |11pt| argument is optional, whereas the |article| class name is
mandatory.
In LATEX~2.09 users could define commands with arguments, but these
had to be mandatory arguments. With LATEX2e, users can now define
commands and environments which also have one optional argument.
#decl247#
These commands have a new, second, optional argument; this is used for
defining commands which themselves take one optional argument. This
new argument is best introduced by means of a simple (and hence not
very practical) example:
verbatim46#
This defines || to be a command with two arguments, referred
to as |#1| and |#2| in the <#259#>definition<#259#>---nothing new so far. But
by adding a second optional argument to this | | (the
|[YYY]|) the first argument (|#1|) of the newly defined command
|| is made optional with its default value being |YYY|.
Thus the usage of || is either:
verbatim47#
which prints:
Mandatory arg: BBB;
Optional arg: YYY.
or:
verbatim48#
which prints:
Mandatory arg: AAA;
Optional arg: XXX.
The default value of the optional argument is YYY.
This value is specified as the <#269#>default<#269#> argument of the
| | that created ||.
As another more useful example, the definition:
verbatim49#
means that the input |#tex2html_wrap_inline1995#a| produces
the formula #math68#{a0,…, an},
whereas the input |#math69##tex2html_wrap_inline1998#[k]x| produces the formula
#math70#{x0,…, xk}.
In summary, the command:
| | <#279#>cmd<#279#> <#280#>num<#280#> <#281#>default<#281#> <#282#>definition<#282#>
defines <#284#>cmd<#284#> to be a command with <#285#>num<#285#> arguments, the first of
which is optional and has default value <#286#>default<#286#>.
Note that there can only be one optional argument but, as before,
there can be up to nine arguments in total.
#decl287#
LATEX2e also supports the creation of environments that have one
optional argument. Thus the syntax of these two commands has
been extended in the same way as that of | |.
#decl299#
This takes the same arguments as | |. If <#305#>cmd<#305#> is already
defined then the existing definition is kept; but if it is currently
undefined then the effect of |is to define <#306#>cmd<#306#>
just as if | | had been used.
#NEWfeature307#